import time

from selenium.webdriver.common.by import By

from page.page01_tpshop_login import login, search, click_search
from tools import web_driver, driver_quit


def test_login_success():
    driver = web_driver()
    login(driver, '13400000011', '123456', '8888')
    time.sleep(3)
    information = driver.find_element(by=By.LINK_TEXT, value="安全退出").text
    assert "安全退出" == information
    driver_quit(driver)

def test_search_success():
    driver = web_driver()
    search(driver, "手机")
    information = driver.find_element(by=By.XPATH, value="/html/body/div[2]/div/div[1]/a[2]").text
    assert "手机" == information
    driver_quit(driver)

def test_click_search_success():
    driver = web_driver()
    click_search(driver)
    # 切换窗口
    handles = driver.window_handles
    driver.switch_to.window(handles[1])
    information = driver.find_element(by=By.XPATH, value="/html/body/div[2]/div/div[1]/div[2]/div[1]/span").text
    assert "手写板" == information
    driver_quit(driver)
